package com.jmlee.service.impl;

import com.jmlee.mapper.ACategoryMapper;
import com.jmlee.pojo.ACategory;
import com.jmlee.service.ACategoryService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class ACategoryServiceImpl implements ACategoryService {
    @Autowired
    ACategoryMapper aCategoryMapper;
    @Override
    public List<ACategory> getAllCategory(RowBounds rowBounds, ACategory aCategory) {
        if (rowBounds == null && aCategory != null){
            return aCategoryMapper.selectCategory(aCategory);
        }
        if (aCategory == null && rowBounds != null){
            return aCategoryMapper.selectCategory(rowBounds);
        }
        if (rowBounds == null && aCategory == null) {
            return aCategoryMapper.selectCategory();
        }
        return aCategoryMapper.selectCategory(rowBounds,aCategory);
    }

    @Override
    public List<ACategory> getAllChildCategory() {
        return aCategoryMapper.selectChildCategory();
    }


    @Override
    public Integer editCategory(ACategory aCategory) {
        return aCategoryMapper.updateCategory(aCategory);
    }

    @Override
    public Integer delCategory(ACategory aCategory) {
        aCategory.setStatus(2);
        return aCategoryMapper.updateCategory(aCategory);
    }


    @Override
    public Long getCountOfCategory(ACategory aCategory) {
        return aCategoryMapper.selectCategoryCount(aCategory);
    }

    @Override
    public Integer addNewCategory(ACategory aCategory) {
        aCategory.setCreateTime(new Date());
        return aCategoryMapper.insertCategory(aCategory);
    }


}
